#####################################################################
#Program for to get Loglik. for the model when \alpha_1(X,Z) and \alpha_2(X,Z) are probit function. (Method 5)
#####################################################################

probit.lf <- function(beta) {
  
  F0 <- pnorm(X0%*%beta[1:2]) 
  F1 <- pnorm(X1%*%beta[3:5]) 
  F2 <- pnorm(X2%*%beta[6:8]) 
  
  
  y00 <- (1 - y1)*(1 - y2)
  y01 <- (1 - y1)*y2
  y10 <- y1*(1 - y2) 
  y11<- y1*y2
  
  
  prob00 <- 1 - F0 + F1*F2*F0 
  logprob00 <- log(prob00)
  
  prob01 <- F1*(1-F2)*F0
  logprob01 <- log(prob01)
  
  prob10 <-  (1- F1)*F2*F0
  logprob10 <- log(prob10)
  
  prob11 <-  (1- F1)*(1-F2)*F0
  logprob11 <- log(prob11)
  
  y00t <- t(y00)
  y01t <- t(y01)
  y10t <- t(y10)
  y11t <- t(y11)
  
  logl <- -sum(y00t%*%logprob00 + y01t%*%logprob01 + y10t%*%logprob10 + y11t%*%logprob11)
  return(logl)
}
